package com.howie.shirojwt.anno;

import org.reflections.Reflections;
import org.reflections.scanners.MethodAnnotationsScanner;
import org.reflections.scanners.MethodParameterNamesScanner;
import org.reflections.scanners.SubTypesScanner;
import org.reflections.scanners.TypeAnnotationsScanner;
import org.springframework.web.bind.annotation.RestController;

import java.lang.reflect.Method;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;

public final class AnnoManageUtils {
  /**
   * 所有的权限定义
   */
  public static Map<String, String> map = new ConcurrentHashMap<String, String>();

  /**
   * 用户权限定义
   */
  public static Map<String, Set> userPerMap = new ConcurrentHashMap<String, Set>();
  static {


  }

  public static Set getUserPer(String user){
    //反射工具包，指明扫描路径
//    Reflections reflections = new Reflections("com.howie.shirojwt.controller");
    Reflections reflections = new Reflections("com.howie.shirojwt.controller", new MethodAnnotationsScanner(), new TypeAnnotationsScanner(), new SubTypesScanner(), new MethodParameterNamesScanner());
    //获取带注解的类
//    Set<Class<?>> aaa=reflections.getTypesAnnotatedWith(RestController.class);
    //获取带注解的方法
    Set<Method> list = reflections.getMethodsAnnotatedWith(RequiresDefine.class);
    for (Method method : list) {
      RequiresDefine t = (RequiresDefine) method.getAnnotation(RequiresDefine.class);
      String value = t.value();

      //注解值为key，类名为value
      map.put(value, method.getName());

    }
    /**
     * 测试  设置用户ding的权限
     */
    Set a=new HashSet<String>();
    a.add("com.shirojwt.controller.getDefMessage");
    userPerMap.put("ding",a);
    userPerMap.put("wang",map.keySet());
    return userPerMap.get(user);
  }




}